package io.onedev.server.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(
		indexes={@Index(columnList="o_user_id"), @Index(columnList="o_provider_id"), @Index(columnList=SsoAccount.PROP_SUBJECT)},
		uniqueConstraints={@UniqueConstraint(columnNames={"o_provider_id", SsoAccount.PROP_SUBJECT})
})
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class SsoAccount extends AbstractEntity {

	private static final long serialVersionUID = 1L;
	
	public static final String PROP_USER = "user";
	
	public static final String PROP_PROVIDER = "provider";

	public static final String PROP_SUBJECT = "subject";

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(nullable=false)
	private User user;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(nullable=false)
	private SsoProvider provider;

	@Column(nullable=false)
	private String subject;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public SsoProvider getProvider() {
		return provider;
	}

	public void setProvider(SsoProvider provider) {
		this.provider = provider;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

}
